#include "regx51.h"
#include "math.h"

//#define Work2

#define Common_cathode  //共阴极



void Delay_ms(unsigned int t);

unsigned char code LED_Table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
                                //0  1  2  3  4  5  6  7  8  9
                                ,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40,0x00};
                                //A  B  C  D  E  F  -  Down

unsigned char data LED_Seg_DisNum[6]={0};


void Show_Seg8_Unsigend_Num(unsigned long int num)
{
    unsigned char scan=0xfe;
    unsigned char i=0;
    LED_Seg_DisNum[0]=num/100000;
    num%=100000;
    LED_Seg_DisNum[1]=num/10000;
    num%=10000;
    LED_Seg_DisNum[2]=num/1000;
    num%=1000;
    LED_Seg_DisNum[3]=num/100;
    num%=100;
    LED_Seg_DisNum[4]=num/10;
    num%=10;
    LED_Seg_DisNum[5]=num/1;

    for(i=0;i<6;i++)
    {
        P2=0xff;
        P0=LED_Table[LED_Seg_DisNum[i]];
        P2=scan;
        scan=(scan<<1)+1;
        Delay_ms(5);
    }

}


void Delay_ms(unsigned int t)
{
    unsigned int i,j;
    for(i=0;i<t;i++)
    {
        for(j=0;j<100;j++)
        {
            ;
        }
    }
}

void Timer_Init(void)
{
	TMOD=0x02;
    TL0=0x9c;
    TH0=0x9c;
    ET0=1;
    EA=1;
    TR0=1;
}

unsigned long int a=123456;
void main()
{
    #ifdef Work2
    Timer_Init();
    #endif
    while(1)
    {
        Show_Seg8_Unsigend_Num(a);
    }
}

void Timer0_ISR(void) interrupt 1
{
    static unsigned int Count=0;
    Count++;
    if(Count==10000)
    {
        Count=0;
        a++;
    }
}
